/***
 * 此util主要提供
 */
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
import { Course } from '../entity/Course';
import CourseService from '../service/CourseService';
import CourseUtil from './CourseUtil';
import PreferencesUtil from "../service/PreferenceUtil"
import Constants from "../constants/Constants"

class FormUtil{

  updateFormData(formId:string){
    let formData = this.getFormData();
    let formInfo = formBindingData.createFormBindingData(formData)
    formProvider.updateForm(formId, formInfo).then((data) => {
      console.info('FormAbility updateForm success.' + JSON.stringify(data));
    }).catch((error:Error) => {
      console.error('FormAbility updateForm failed: ' + JSON.stringify(error));
    })
  }

  async getFormData(){
    let courseFormList:Array<Course> = await CourseUtil.filterFormWeekCourse(await CourseService.queryCourseData());
    let formData = {
      'secudleName': PreferencesUtil.getPreferenceValue("secudleName","课表"), // 和卡片布局中对应
      'courseList':Constants.courseFormList
    };
    return formData;
  }

}

let formUtil = new FormUtil();
export default formUtil as FormUtil;